package com.zpark.dao.impl;

import com.zpark.dao.IAccountDao;
import com.zpark.pojo.Account;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

/**
 * 账户持久层接口实现类
 */
@Repository
public class AccountDaoImpl implements IAccountDao {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public Account selectById(Integer id) {
        String sql = "select id, uid, money from account where id=?";
        return jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper<>(Account.class), id);
    }

    @Override
    public Integer updateById(Integer id, Double money) {
        String sql = "update account set money=? where id=?";
        return jdbcTemplate.update(sql, money, id);
    }
}
